﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.member;

namespace SocialFront.Web.usercontrols.Membership
{
    public partial class MembershipChangePassword : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                
                //Guid userGuid;
                //if (Screenmedia.Lib.GuidTryParse(Request.QueryString["guid"], out userGuid))
                //{

                //    NoGuid.Visible = false;
                //    FormReset.Visible = true;

                //}
            }
        }

        private const string errorOutput = "The details entered are incorect please try again.";

        protected void CheckUserInfo_Click(object sender, EventArgs e)
        {
            //Guid userGuid;
            //if (Screenmedia.Lib.GuidTryParse(Request.QueryString["guid"], out userGuid))
            //{
            //    Member chosenMember = Member.GetMemberFromEmail(EmailAddress.Text);
            //    if (chosenMember != null)
            //    {
            //        Guid userDbGuid;
            //        if (Screenmedia.Lib.GuidTryParse(chosenMember.getProperty("PasswordRecoveryKey").Value.ToString(),
            //                                         out userDbGuid))
            //        {

            //            bool isGuidKeyCorrect =
            //                userGuid.Equals(userDbGuid);

            //            bool isUsernameCorrect = (chosenMember.LoginName.ToLower() == Username.Text.ToLower());

            //            if (isGuidKeyCorrect && isUsernameCorrect)
            //            {
            //                FormReset.Visible = false;
            //                ChangePassword.Visible = true;

            //                ViewState.Add("usrUsername", chosenMember.LoginName);
            //                ViewState.Add("usrEmail", chosenMember.Email);
            //                ViewState.Add("usrGuid", userDbGuid.ToString());
            //            }
            //            else
            //            {
            //                error.Visible = true;
            //                mailError.Text = errorOutput;
            //            }
            //        }
            //    }
            //    else
            //    {
            //        error.Visible = true;
            //        mailError.Text = errorOutput;
            //    }
            //}
        }

        protected void ConfirmResetPassword_Click(object sender, EventArgs e)
        {
            //string sUsername = (string)ViewState["usrUsername"];
            //string uEmail = (string)ViewState["usrEmail"];
            //string uGuid = (string)ViewState["usrGuid"];

            //Member chosenMember = Member.GetMemberFromEmail(uEmail);
            //if (chosenMember != null)
            //{
            //    chosenMember.Password = Password.Text;
            //    //chosenMember.ChangePassword(Password.Text);
            //    chosenMember.XmlGenerate(new System.Xml.XmlDocument());

            //    chosenMember.getProperty("PasswordRecoveryKey").Value = "";

            //    chosenMember.Save();

            //    ChangePassword.Visible = false;
            //    ResetComplete.Visible = true;
            //}
        }

    }
}